package com.symria.client.common;

import java.util.Date;

import com.symria.framework.page.ATTPage;
import com.symria.framework.page.Page;
import com.symria.framework.page.PagerFactory;
import com.symria.framework.util.BaseAction;
import com.symria.framework.util.DateUtil;
import com.symria.server.bo.common.IosService;
import com.symria.server.po.IosActivate;
import com.symria.server.po.IosAdConfig;
import com.symria.server.po.IosChannelConfig;
import com.symria.server.po.IosClick;
public class IosAction extends BaseAction {
	private IosAdConfig config;
	private IosChannelConfig channel;
	private IosChannelConfig channelConfig;
	private IosService iosService;
	private Integer id;
	private IosClick click;
	private Date beginDate,endDate;
	private IosActivate activate;
	
	public String searchAdConfig(){
		Page page = PagerFactory.createPage();
		iosService.searchAdConfig(config, page);
		setAttr(ATTPage.PAGE_LIST, page);
		return SUCCESS;
	}

	public String searchChannelConfig(){
		Page page = PagerFactory.createPage();
		iosService.searchChannelConfig(channelConfig, page);
		setAttr(ATTPage.PAGE_LIST, page);
		return SUCCESS;
	}
	public String toAdConfig(){
		IosAdConfig config = iosService.getObject(id, IosAdConfig.class);
		setAttr("config", config);
		return SUCCESS;
	}
	public String toChannelConfig(){
		IosChannelConfig c = iosService.getObject(id, IosChannelConfig.class);
	    setAttr("channel", c);
		return SUCCESS;
	}
	public String suChannelConfig(){
		IosChannelConfig c = iosService.getObject(id, IosChannelConfig.class);
		if(c!=null){
			iosService.updateChannelConfig(c, channel);
		}
		return SUCCESS;
	}
	public String suAdConfig(){
		IosAdConfig c = iosService.getObject(id, IosAdConfig.class);
		if(c!=null){
			iosService.updateAdConfig(c, config);
		}
		return SUCCESS;
	}
	public String searchIosClick(){
		Page page = PagerFactory.createPage();
		iosService.searchIosClick(page, click, beginDate, endDate);
		setAttr(ATTPage.PAGE_LIST, page);
		setAttr("adlist", iosService.queryAdConfig());
		setAttr("channellist", iosService.queryChannelConfig());
		return SUCCESS;
	}
	public String searchIosActivate(){
		Page page = PagerFactory.createPage();
		iosService.searchIosActivate(page, activate, beginDate, endDate);
		setAttr(ATTPage.PAGE_LIST, page);
		return SUCCESS;
	}
	public String searchIosDaily(){
		Page page = PagerFactory.createPage();
		String appId=click!=null?click.getAppId():null;
		String channel =click!=null?click.getChannel():null;
		
		if(null==beginDate){
			beginDate = DateUtil.absoluteDate(new Date(), -7);
		}
		if(null==endDate){
			endDate = new Date();
		}
		
		
		iosService.searchIosDaily(page, appId, channel, beginDate, endDate);
		setAttr(ATTPage.PAGE_LIST,page);
		setAttr("adlist", iosService.queryAdConfig());
		setAttr("channellist", iosService.queryChannelConfig());
		return SUCCESS;
	}
	
	
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public IosAdConfig getConfig() {
		return config;
	}

	public void setConfig(IosAdConfig config) {
		this.config = config;
	}

	public IosChannelConfig getChannelConfig() {
		return channelConfig;
	}

	public void setChannelConfig(IosChannelConfig channelConfig) {
		this.channelConfig = channelConfig;
	}

	public IosService getIosService() {
		return iosService;
	}

	public void setIosService(IosService iosService) {
		this.iosService = iosService;
	}

	public IosChannelConfig getChannel() {
		return channel;
	}

	public void setChannel(IosChannelConfig channel) {
		this.channel = channel;
	}

	public IosClick getClick() {
		return click;
	}

	public void setClick(IosClick click) {
		this.click = click;
	}

	public Date getBeginDate() {
		return beginDate;
	}

	public void setBeginDate(Date beginDate) {
		this.beginDate = beginDate;
	}

	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	public IosActivate getActivate() {
		return activate;
	}

	public void setActivate(IosActivate activate) {
		this.activate = activate;
	}
	
}
